package com.example.a10928.weifriend.adapter

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context.CLIPBOARD_SERVICE
import android.support.v4.content.ContextCompat.getSystemService
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.a10928.weifriend.App.activity
import com.example.a10928.weifriend.R
import com.example.a10928.weifriend.http.api.base.CustomerServiceBean
import com.example.a10928.weifriend.ui.DatabindingBaseActivity
import com.example.a10928.weifriend.util.L
import kotlinx.android.synthetic.main.item_service_data.view.*

class ServiceAdapter(layoutRes: Int, data: List<CustomerServiceBean.CustomerDataServiceBean>) :
        BaseQuickAdapter<CustomerServiceBean.CustomerDataServiceBean, BaseViewHolder>(layoutRes, data) {

    override fun convert(helper: BaseViewHolder?, item: CustomerServiceBean.CustomerDataServiceBean?) {
        val tv = helper!!.getView<TextView>(R.id.service_tv)
        val iv = helper!!.getView<ImageView>(R.id.service_copy)
        iv.setOnClickListener {
            val myClipboard = activity.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
            val myClip: ClipData
            myClip = ClipData.newPlainText(item!!.account, item!!.account)
            myClipboard.primaryClip = myClip
            L.t("复制成功")
        }
        when (item!!.type) {
            1, 2 -> { //QQ  2 //微信
                tv.setCompoundDrawablesWithIntrinsicBounds(activity.resources.getDrawable(R.drawable.service_wechat), null, null, null)
                tv.text = "微信: 客服" + item.id+ " " + item.account
            }
            3 -> { //电话
                tv.setCompoundDrawablesWithIntrinsicBounds(activity.resources.getDrawable(R.drawable.service_tel), null, null, null)
                tv.text = "电话: " +item.account
            }
        }

    }

}